package io.renren.modules.workmanagement.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.sys.controller.AbstractController;
import io.renren.modules.workmanagement.entity.StudentEntity;
import io.renren.modules.workmanagement.service.StudentService;
import io.renren.modules.workmanagement.vo.AddStudentVO;
import io.renren.modules.workmanagement.vo.BatchAddStudentVO;
import io.renren.modules.workmanagement.vo.StudentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 *
 *
 * @author yewei
 * @email sunlightcs@gmail.com
 * @date 2022-04-23 21:11:24
 */
@RestController
@RequestMapping("workmanagement/student")
public class StudentController extends AbstractController {
    @Autowired
    private StudentService studentService;

    @PostMapping("/batchAddStudent")
    public R batchAddStudent(@RequestBody BatchAddStudentVO batchAddStudentVO){
        studentService.batchAddStudent(batchAddStudentVO,getUserId());
        return R.ok();
    }
    /**
     * 列表
     */
    @RequestMapping("/getByClassId")
    public R getByClassId(@RequestParam Long classId){
        List<StudentVO> students = studentService.getListByClassId(classId);

        return R.ok().put("students", students);
    }
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = studentService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		StudentEntity student = studentService.getById(id);

        return R.ok().put("student", student);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody StudentEntity student){
		studentService.save(student);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody StudentEntity student){
		studentService.updateById(student);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		studentService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @PostMapping("/addStudent")
    public R addStudent(@RequestBody AddStudentVO addStudentVO){
        studentService.addStudent(addStudentVO,getUserId());
        return R.ok();
    }

    @PostMapping("/updateStudent")
    public R updateStudent(@RequestBody AddStudentVO addStudentVO){
        studentService.updateStudent(addStudentVO);
        return R.ok();
    }

    @DeleteMapping("/deleteStudent")
    public R updateStudent(@RequestParam Long stuNo,@RequestParam Long classId){
        studentService.deleteStudent(stuNo,classId);
        return R.ok();
    }
}
